﻿namespace BlogsAPI.LivejournalRPC
{
    using CookComputing.XmlRpc;
    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    [XmlRpcUrl("http://www.livejournal.com/interface/xmlrpc")]
    public interface ILj : IXmlRpcProxy
    {
        [XmlRpcMethod("LJ.XMLRPC.login")]
        LjUserInfo Login(UserAccount user);

        [XmlRpcMethod("LJ.XMLRPC.postevent")]
        PostLjAnswer Post(PostLj post);
    }

    public class PostLjAnswer
    {
        public int anum { get; set; }

        public int itemid { get; set; }

        [XmlRpcMissingMapping(MappingAction.Ignore)]
        public string url { get; set; }
    }

    /// <summary>
    /// Бесполезная информация о пользователей ЖЖ
    /// </summary>
    [JsonObject]
    public class LjUserInfo
    {
        [JsonProperty("userid")]
        public int userid { get; set; }

        [JsonIgnore]
        [XmlRpcMissingMapping(MappingAction.Ignore)]
        public string message { get; set; }

        [JsonProperty("fullname")]
        public string fullname { get; set; }

        [JsonIgnore]
        public FriendgroupLj[] friendgroups { get; set; }

        [JsonIgnore]
        public string[] usejournals { get; set; }
    }

    /// <summary>
    /// Различные группы френдов, которые есть у пользователя
    /// </summary>
    public class FriendgroupLj
    {
        public int id { get; set; }
        public string name { get; set; }
        public int sortorder { get; set; }
        public int @public { get; set; }
    }

    /// <summary>
    /// Опции для поста
    /// </summary>
    public class AttributesLj
    {
        public string taglist = "";
        public string current_mood = "";
        public string current_music = "";
        public string current_location = "";
        public bool opt_preformatted = true;
        public string adult_content = "";
    }


    /// <summary>
    /// Постинг в никуда
    /// </summary>
    public class PostLj : UserAccount
    {
        public const string lineendings = "pc";
        public const int ver = 1;

        public string @event { get; set; }
        public string subject { get; set; }
        
        public int year { get; set; }
        public int mon { get; set; }
        public int day { get; set; }
        public int hour { get; set; }
        public int min { get; set; }
        public string usejournal { get; set; }
        public string security { get; set; }

        public AttributesLj props { get; set; }

    }
}
